package com.lanhai.fnstore.log;
 

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.lanhai.fnstore.Config;
import com.lanhai.fnstore.Tools;

public class LogThread {
	private boolean running;
	private Thread th; 
	private String logurl;
	private Gson gson;
	
	public LogThread(Config conf) {
		logurl=conf.getLogurl();
		gson=new Gson();
	}
	
	
	public void Start( ) {
		running = true;
		th = new Thread() {
			@Override
			public void run() {
 
				while (running) {
					LogData[] arr=LogQueue.Pop();
					 
					if(arr!=null&&logurl.isBlank()==false ) {
						List<LogData> list=new ArrayList<LogData>();
						for(LogData dd:arr) {
							list.add(dd);
						}
						LogTemp lt=new LogTemp();
						lt.setList(list);
						 String  json=gson.toJson(lt);
						 Tools.post(logurl, json); 
					} 
					try {
						Thread.sleep(500);
					} catch (Exception ex) {

					}
				}
			}

		};
		th.start();
	}

	public void Stop() {
		running = false;
		try {
			th.interrupt();
			th = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

class LogTemp{
	private List<LogData> list;

	public List<LogData> getList() {
		return list;
	}

	public void setList(List<LogData> list) {
		this.list = list;
	}
	
	
}

 